package com.hyj.jpdy.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyj.jpdy.bean.vo.Article;
import com.hyj.jpdy.dao.ICommonDAO;
import com.hyj.jpdy.service.IGrapService;

@Service
public class GrapService implements IGrapService {

	@Autowired
    private ICommonDAO dao;
	
	@Override
	public void saveArticle(Article a) {
		// 检查有木有重复的文章
		String  sql =  " SELECT count(1) FROM t_joke t WHERE t.fromurl = ? AND t.cateid = ? ";
		int num =  dao.queryForInt(sql, new Object[]{a.getFromUrl(),a.getTypeId()});
		
		if(num<=0){
		sql = "  INSERT INTO  t_joke (title,author,fromurl,content,cateid,ADDTIME,pubdate) " +
				     "  VALUES(?,?,?,?,?,?,?) ";
		Object[] args = new Object[]{a.getTitle(),a.getColumnName(),a.getFromUrl(),a.getContent(),a.getTypeId(),new Date(),a.getPubDate()};
		dao.update(sql, args);
		}
	}

	@Override
	public List<Map<String, Object>> queryJokeColumn() {
		
		String sql = " SELECT t.url,t.categoreId,t.STATUS,t.modleId FROM  t_joke_column t WHERE t.STATUS = 0  ";
		return  dao.queryForList(sql);
		
	}
	
	
	@Override
	public void saveItemInfo(Article a) {
		// 检查有木有重复的文章
		String  sql =  " SELECT count(1) FROM tb_item_info_list t WHERE t.FromUrl = ? AND t.ColumnID = ? ";
		int num =  dao.queryForInt(sql, new Object[]{a.getFromUrl(),a.getColumnId()});
		
		if(num<=0){
		sql = "  INSERT INTO  tb_item_info_list (Title,ColumnID,ItemID,FromUrl,Content,CategoryID,CreateDate,PubDate) " +
				     "  VALUES(?,?,?,?,?,?,?,?) ";
		Object[] args = new Object[]{a.getTitle(),a.getColumnId(),a.getItemID(),a.getFromUrl(),a.getContent(),a.getTypeId(),new Date(),a.getPubDate()};
		dao.update(sql, args);
		}
	}
	
	

}
